package com.smartleanx.module.hrm.controller.admin.esign;

import com.alibaba.excel.EasyExcel;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.module.hrm.dal.dataobject.esign.ContractOrder;
import com.smartleanx.module.hrm.service.esign.bo.ContractOrderSelectBo;
import com.smartleanx.module.hrm.service.esign.service.ContractOrderService;
import com.smartleanx.module.hrm.service.esign.vo.ContractOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;

@RestController
@RequestMapping("/hrm/contractOrder")
public class ContractOrderController {

    @Autowired
    private ContractOrderService contractOrderService;

    @PostMapping("/selectPage")
    public CommonResult<Object> selectPage(@RequestBody ContractOrderSelectBo contractOrderSelectBo) {
        return CommonResult.success(contractOrderService.selectPage(contractOrderSelectBo));
    }

    @PostMapping("/selectListExcel")
    public void  selectListExcel(ContractOrderSelectBo contractOrderSelectBo, HttpServletResponse response) throws Exception {
        List<ContractOrderVo> contractOrders = contractOrderService.selectListExcel(contractOrderSelectBo);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("数据导出.xlsx", "utf-8"));
        EasyExcel.write(response.getOutputStream(), ContractOrderVo.class).sheet("模板").doWrite(contractOrders);
    }







}
